Method of controlling flash memory

ABSTRACT

In order to control efficiently a flash memory in the case where small-scale data are frequently rewritten, a method of controlling a flash memory in which a data storage region is divided into unit sectors and data can be erased by every sector as a unit, is configured that the sector comprises a sector control region and a plurality of pages, and included are both available/unavailable flag information about the page concerned and an occupied/unoccupied map showing a data storage location of the data storage region on the page concerned. By employing such a configuration, it is easy to decide whether the page referred to is available or unavailable and the configuration is suitable for frequently renewing and adding pages, which are of a large quantity and on a small scale.

BACKGROUND OF THE INVENTION

[0001] 1. Field of the Invention

[0002] The present invention relates to a method of controlling a flashmemory, especially a method of controlling a flash memory useful forrewriting of small-scale data used in a cellular phone, etc.

[0003] 2. Description of the Related Art

[0004] Conventionally, in the field of flash memories, a minimum uniterased by 1 flash is referred to a sector and a flash memory has beencontrolled by the sector as a unit. However, when the size of dataprocessed is as small as that of small-scale data containing a few bitesor so such as an IP address, a MAC (Machine Address Code) address, thesize of 1 sector has been an issue from the viewpoint of the efficiencyof controlling memories in the application where such small-scale dataare frequently accessed.

[0005]FIG. 1A is a diagram showing an example of the constitution of aconventional flash memory using the sector as the unit and it isconfigured that a file is divided into sectors 701, and a sector controlregion 702 is provided at the head of each sector, and the number oferasure-times and the information about a party linked to the sector arewritten in the control region. With regard to such a control method, forexample, in JP, 2002-7221, A described is that a sector is dividedfurther into smaller blocks and a writing decision region, representingwhether the block concerned is already written thereon or not, isprovided for each block at its head, and in JP, 2001-312891, A describedis that a memory is divided into blocks and a control status writingarea is provided for each memory block, and in JP, 08-273390, Adescribed is that a block storage area for the data of the number oferasure times is provided for each block at its head.

[0006]FIG. 1B shows a method of controlling a memory described in JP,2000-76117, A and each sector is composed of a plurality of small blocks703, and each small block comprising 256 bytes is composed of a controlregion 704 with 6 bytes and a data storage region with 250 bytes. Thecontrol region 704 in this case comprises a file number 706, a sectornumber 707 of the following storage portion, a small block address 708showing the linkage to other small blocks, and an available/unavailablecode 709 representing whether the data of the small block are availableor unavailable.

[0007] However, by means of the conventional methods above, whensmall-scale data are frequently rewritten in such an application as toenclose a small-scale data like an IP address of the Internet in a flashmemory inside a cellular phone, working efficiency of the memory may nothave been said to be sufficient.

SUMMARY OF THE INVENTION

[0008] In order to control efficiently a flash memory in the case wheresmall-scale data are frequently rewritten, a method of controlling aflash memory in which a data storage region is divided into unit sectorsand data can be erased by every sector as a unit, is configured that thesector comprises a sector control region and a plurality of pages, andincluded are both available/unavailable flag information about the pageconcerned and an occupied/unoccupied map showing a data storage locationof the data storage region on the page concerned. By employing such aconfiguration, it is easy to decide whether the page referred to isavailable or unavailable and the configuration is suitable forfrequently renewing and adding pages, which are of a large quantity andon a small scale.

BRIEF DESCRIPTION OF THE DRAWINGS

[0009]FIGS. 1A, 1B are illustrations of conventional art.

[0010]FIGS. 2A, 2B, 2C are diagrams showing the structure of data in the1st embodiment of the present invention.

[0011]FIG. 3 is an operation (sector control) flow diagram of a controlprogram in the 1st embodiment.

[0012]FIG. 4 is an operation (data writing) flow diagram of the controlprogram in the 1st embodiment.

[0013]FIG. 5 is an operation (data read-in) flow diagram of the controlprogram in the 1st embodiment.

[0014]FIGS. 6A, 6B are diagrams showing the structure of data in the 2ndembodiment.

[0015]FIGS. 7A, 7B are diagrams showing the structure of data in the 3rdembodiment.

[0016]FIGS. 8A, 8B, 8C are diagrams showing the general structure ofpage control regions in the 1st, 2nd, 3rd embodiment respectively.

DETAILED DESCRIPTION OF THE INVENTION

[0017] In the following, the embodiments of the present invention willbe described using the drawings. Besides, in the drawings, the size, theshape, the configuration, etc. of each constituent are shown only soschematically as to understand the present invention, and numericalrequirements described below are given as mere illustrations.

[0018] [1st Embodiment]

[0019]FIG. 2A shows the structure of a sector of a flash memory in the1st embodiment of the present invention, and the interior of 1 sector101, an erasure unit of the flash memory is configured to be dividedinto a sector control region 102 and a number of pages 103. In thesector control region 102 included are pieces of information such as anavailable/unavailable flag showing whether the sector is already used upor not, the number of erasure times.

[0020] The 1 page is divided into a page control region 104 and a dataregion 107, and the page control region is composed of anavailable/unavailable flag 105 and a occupied/unoccupied map 106. Inthis embodiment, the 1 sector (32 k bytes) is divided into 1024 pages,and the sector control region is assigned to one of the pages, and theremaining 1023 pages are used as the data region. Further, as shown inFIG. 2B, each page 103 is composed of 32 bytes, and the page controlregion 104 comprises 2 bytes in which 1 bit is used for theavailable/unavailable flag and the remaining 15 bits are used for theused/unused map. Therefore, the data capacity of each page is 30 bytes.

[0021] The meaning of the available/unavailable flag is as follows. Thatis to say, when the bit value is “1” it represents that the data is atthe state as initialized, and when “0” it represents that the data isunavailable and has been excluded already.

[0022] With regard to the occupied/unoccupied map 106, all the bits are“1” at the initial state, and each bit represents that the correspondingword in the data region is unused when the bit is “1”, and that thecorresponding word in the data region is now used when the bit is “0”.Accordingly, at the initial state, namely the state immediately aftererasure of the sector concerned, all the pages composing the sector areavailable and unused at the same time.

[0023]FIG. 2C shows an example of page data, and the fact that theavailable/unavailable flag is “1” shows that this page is availableincluding available data therein. With regard to the followingoccupied/unoccupied map according to the example shown in the figure,since 6 bits at the head is are “0” and 9 bits at the back are “1”, itis shown that 6 words (12 bytes) at the head in the data region are nowoccupied and 9 words (18 bytes) at the back are an unoccupied region.All the bits of the data in the unused region are “1”.

[0024] When writing is executed on a flash memory, the writing can bedone by 1 byte or by 1 word as a unit by means of specifying the addressthereof. In the example of the data structure shown in this embodiment,when both control data and essential data are accessed, a method ofaccessing by every 1 word is preferable. Further, since 1 page comprises32 bytes (16 words), it is advantageous when the sectors are dividedinto the pages.

[0025] In the case where necessity of adding new data occurs, 2 methodsof how to use the pages can be counted in this embodiment. The first oneis a usual writing method wherein an available and unused page isretrieved from the head of the sector concerned and then the data iswritten into the unused sites of the occupied/unoccupied map. In thecase where the page is filled and data cannot be added therein, it turnsnecessary to write the data from the head of a new page and it isrecorded, by setting the bit concerned of the occupied/unoccupied map to“1”, that the region used at the moment is now occupied. The second one,in the case where data about the same information has been writtenalready and the data must be renewed, is a method for renewing datawherein the page concerned is made unavailable by setting theavailable/unavailable flag to “0” while data of the page are read out atanother location, and the page is renewed with the data read outbeforehand at another location and then the data is written in anunoccupied page. However, the renewal is intended only for the data andoverwriting at the same location is not performed.

[0026] Since the sector concerned is not yet erased during theseoperations, the data can be renewed promptly. Further, since excluding(making unavailable) the data is executed by the page as a unit and thedata on the page are controlled by the word, the memory region can beused without waste compared to the conventional small block structure.

[0027]FIG. 3-FIG. 5 shows the operation flow of the memory controlprogram in the 1st embodiment, and FIG. 3 is a control flow diagramshowing how the control program controls sectors composing a file.

[0028] Starting from a variable K=0 (S201), the K-th sector of the fileis decided available/unavailable by means of said flag (S202). If thesector is not available at the time, the variable K is stepped forwardat the step S208, returning to the step S202 in order to examine thenext sector, and if the sector is available at the step S203, all thepages of the sector are decided whether they are unavailable or not(S204). If all the pages are unavailable, the number of erasure times isdecided at the step S205 whether it is within the limit or not, and ifit is within the limit, the sector concerned is erased in order toreutilize itself adding 1 to the number of erasure times of the sectorin the sector control region 104 (S206), and if it is beyond the limit,the sector concerned is made unavailable (S207) returning to the stepS208 in order to retrieve the next sector.

[0029] At the step S204, if there is any available pages for the presentsector, the contents of the present operation is examined to decidewhether it is reading out or not (S209), and if it is reading out, areadout operation is executed (S210), and if not, the operation isexamined whether it is writing or not (S211), and if it is writing, awriting operation is executed (S212), and if it is neither the readoutnor the writing, the operation is ceased (S213).

[0030]FIG. 4 is a writing flow diagram along which the control programwrites data on an available page. Starting as a variable P=0 (S221), theP-th page is decided by means of the available/unavailable flag (S222,S223). If the page is unavailable, the variable P is stepped forward atthe step S224, returning to the step S222 in order to examine the nextpage, and if the page is available, the present writing operation isexamined whether it is renewal of the data or not (S225), and if it isthe renewal of the data, whether there is any renewal data or not isexamined (S226), and if there is any renewal data in the page, while therenewal data is stored for a time, the data is written (S228) aftermaking the page concerned unavailable (S227). Here, the renewal means torenew the data by writing them on an unoccupied page and overwriting atthe same location is not performed.

[0031] At the step S226, if there is not any data concerned for renewal,the operation returns to the step S224 in order to retrieve the nextpage.

[0032] At the step S225, if the present writing operation is not therenewal operation of the data, the page is examined whether it isdataful or not (S229). If it is not dataful, the writing operation isexecuted, and if dataful, the operation returns to the step S224 inorder to retrieve the next page. After completion of the writingoperation (S228) the operation is ceased (S230).

[0033]FIG. 5 is a reading-in flow diagram along which the controlprogram read in data from an available page.

[0034] Starting at a variable P=0 (S241), the page concerned is decidedavailable/unavailable by means of an available/unavailable flag on theP-th page of the sector (S242, S243), and if the page is decided to beunavailable, the variable P is stepped forward at the step S244,returning to the step S242 in order to examine the next page. If thepage is decided to be available at the step S243, it is examined whetherany data concerned exist or not (S245), and if any, a reading-inoperation is executed (S246) to cease the operation (S247). If thereexist no data concerned at the step S245, the operation returns to thestep S244.

[0035] At the steps S226, S245 in the flows of FIGS. 4, 5 it is detectedwhether the data concerned exist or not, and although it turns necessaryto make beforehand the data correspondent to the address of the locationat which they are reserved, the occupied/unoccupied map 106 is used forthe purpose in this embodiment. In the case where theoccupied/unoccupied map 106 is not employed, it should be necessary toprovide another data control region or for the data itself to retain apiece of information, for identifying the self in order to decidewhether the data must be renewed or not. Further, the decision whetherthe page is available or not can be done by means of reading 1 word atthe head of the page to examine the most significant bit of the 1 word.Consequently, unavailable pages can be decided promptly. Further, thedecision whether any writable regions exist on the available page or notcan be done by examining this 1 word at the head.

[0036] [2nd Embodiment]

[0037]FIGS. 6A, 6B are the diagrams showing the 2nd embodiment of thepresent invention, having the structure extended further than the datastructure in the 1st embodiment.

[0038]FIG. 6A shows the structure of a page formed in a sector of aflash memory according to the 2nd embodiment. Here, assigning 4 bytes toa control region 401, 60 bytes to a data region, the entire 1 page 400comprises 64 bytes.

[0039] The control region 401 comprises an available/unavailable flag403, a page extension flag 404, and an occupied/unoccupied map 405. Theavailable/unavailable flag 403 and the occupied/unoccupied map 405correspond to the available/unavailable flag 105 and theoccupied/unoccupied map 106 respectively in the 1st embodiment.

[0040] The page extension flag 404 means that the page concerned isdependent on the 1-page preceding page when it is “0”, and that the pageconcerned is an independent page not dependent on any other pages whenits value is “1”. The available/unavailable flag 403 has priority overthe page extension flag 404. However, since the page extension flag isavailable even when the page has turned unavailable, it is probable thatthere exists a page dependent on the page having turned unavailable.

[0041] In this embodiment, the occupied/unoccupied map comprises 30bits, and the fact means that it can control the data region 402 within30 words.

[0042]FIG. 6B shows an example of the page extended data, and as thepage extension flag on the first page is “1” and the page extensionflags on the following 2 pages are “0”, it represents that the following2 pages are dependent on the 1 page at the head and the total of 3 pagescomposes one body of the data. On the first 2 pages, as all the valuesof the occupied/unoccupied maps are “0”, all the words in the dataregions are occupied, and as only 3 bits at the head in theoccupied/unoccupied map on the last page are “0”, it represents thatonly 3 words (6 bytes) at the head of the data region are occupied.

[0043] Besides, with regard to the structure of data in this embodiment,in order to decide whether the present page is the last page or not, itis necessary to refer to the page extension flag on the next page.

[0044] [3rd Embodiment]

[0045]FIGS. 7A, 7B are the diagrams showing the 3rd embodiment of thepresent invention. According to this embodiment, differing from the 1stand 2nd embodiments, the structure is configured to treat ofvariable-length data.

[0046]FIG. 7A shows the structure of a variable-length page. In thisembodiment, 1 byte is assigned to a control region 501 of thevariable-length page 500 and a data region 502 is of variable-length.The control region 501 comprises an available/unavailable flag 503, apage extension flag 504, and a record length 505. Among these items, theavailable/unavailable flag 503 and the page extension flag 504correspond to the available/unavailable flag 403 and the page extensionflag 404, respectively. Since the record length 505 is introduced, theoccupied/unoccupied map in the 1st and 2nd embodiments is not required.Although a data length can be specified within 64 words at its maximumbecause the record length comprises 6 bits, it is set to 63 bytes at itsmaximum in the present embodiment, for fine setting by the byte andconsidering the total length of a page. Thereby, the maximum length of 1page is 64 bytes.

[0047] Since an occupied region is apparent by making the data length ofvariable-length without employing the occupied/unoccupied map, there isa merit that memory regions can be used without waste. Further, theconfiguration is configured to be convenient for frequently rewritingsmall-scale data.

[0048]FIG. 7B shows an example of a variable-length page data in the 3rdembodiment. The fact that a bit at the head of the control regioncomposed of 1 byte is “1” represents that this page is available, andthe fact that a page extension flag is “1” represents that this page isan independent page and not an extended page. A record length is“100000”, and represents that data length is 32 bytes.

[0049] With regard to the next page, as a bit at the head is “1” itrepresents that this page is available, and as a page extension flag is“0” it represents that this page is an extended page dependent on thepreceding page. Further, as a record length of the page is “010000” itrepresents that the data length is 16 bytes. It is convenient thatsmall-scale data with the same attribute can be added sequentially to anoriginal page with such extended pages.

[0050] Besides, the present invention should not be limited to the aboveembodiment but can be changed into a various form on the basis of thegist of the present invention. For example, in the 1st embodiment,although 1 page comprises 32 bytes including a page control region,which is composed of a available/unavailable flag with 1 bit and anoccupied/unoccupied map with 15 bits, and a data region composed of 30bytes, it can be generalized such that 1 page comprises anavailable/unavailable flag composed of 1 bit, an occupied/unoccupied mapcomposed of m bits selecting the m value in order to make (m+1) bitsequal to 8 times an integer, and the data region composed of 2m bytesfurther selecting in order to make 2m+(1+m)/8=2_(n) bytes (refer to FIG.8A).

[0051] Moreover, in the 2nd embodiment, although 1 page comprises 64bytes including a page control region, which is composed of aavailable/unavailable flag with 1 bit, an page extension flag with 1 bitand an occupied/unoccupied map with 30 bits, and a data region composedof 60 bytes, it can be generalized such that 1 page comprises anavailable/unavailable flag and a page extension flag composed of 1 bitrespectively, an occupied/unoccupied map composed of m bits selectingthe m value in order to make (m+2) bits equal to 8 times an integer, andthe data region composed of 2m bytes further selecting in order to make2m+(2+m)/8=2^(n) bytes (refer to FIG. 8B).

[0052] Further, in the 3rd embodiment, although 1 page comprises 64bytes including a page control region, which is composed of aavailable/unavailable flag with 1 bit, an page extension flag with 1 bitand a record length with 6 bits, and a data region composed of 63 bytes,it can be generalized such that 1 page comprises anavailable/unavailable flag and a page extension flag composed of 1 bitrespectively, a record length composed of m bits selecting the m valuein order to make (m+2) bits equal to 8 times an integer, and the dataregion composed of 2m bytes further selecting in order to make2m+(2+m)/8=2^(n) bytes (refer to FIG. 8C).

What is claimed is:
 1. A method of controlling a flash memory in which adata storage region is divided into unit sectors and the data areerasable by said sector as a unit, wherein said sector comprises asector control region and a plurality of pages, and the control regionof said page includes a piece of available/unavailable flag informationabout the page concerned and an occupied/unoccupied map representing adata storage location of the page concerned in the data storage region.2. The method of claim 1, wherein said 1 page comprises saidavailable/unavailable flag composed of 1 bit, said occupied/unoccupiedmap composed of m bits selecting said m value in order to make (m+1)bits equal to 8 times an integer, and said data region composed of 2mbytes further selecting in order to make 2m+(1+m)/8=2^(n) bytes.
 3. Themethod of claim 1 further comprising the control region of said page towhich a page extension flag, representing whether the page concerned isdependent on the preceding page or not, is added.
 4. The method of claim3, wherein said 1 page comprises said available/unavailable flagcomposed of 1 bit, said occupied/unoccupied map composed of m bits, saidpage extension flag composed of 1 bit selecting said m value in order tomake (m+2) bits equal to 8 times an integer, and said data regioncomposed of 2m bytes further selecting in order to make 2m+(2+m)/8=2^(n)bytes.
 5. A method of controlling a flash memory in which a data storageregion is divided into unit sectors and the data are erasable by saidsector as a unit, wherein said sector comprises a sector control regionand a plurality of pages, and the control region of said page includes apiece of available/unavailable flag information about the pageconcerned, a page extension flag representing whether the page concernedis dependent on the preceding page or not, and a record size informationabout the data region while the record size of said data region isvariable in length.
 6. The method of claim 5, wherein said 1 pagecomprises said available/unavailable flag composed of 1 bit, said pageextension flag composed of 1 bit, said record size information composedof m bits at its maximum selecting said m value in order to make (m+2)bits equal to 8 times an integer, and said data region composed of 2mbytes further selecting in order to make 2m+(2+m)/8=2^(n) bytes.